package com.lw.count;

import java.util.concurrent.CountDownLatch;

/**三个常用的辅助类  CountDownLatch、CyclicBarrier、Semaphore必会！！！！
 * 减法      加法       许可证的数量限制（加减）
 * @author LW
 * @2020/8/20 10:26
 */
//计数器
    //减法      把CountDownLatch的参数count减完     归零等待，再进行下面的
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        //总数是6
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"-----Go out");
                countDownLatch.countDown();//-1
            },String.valueOf(i)).start();
        }
        //这里。六个线程跑完，无论顺序，就会结束
        countDownLatch.await();//等待计数器归零，然后再向下执行
//        countDownLatch.countDown();
        System.out.println("Close Door");

    }
}
